package password

import (
	"ruoyi-go/app/admin/model/constants"
	"ruoyi-go/config"
	"ruoyi-go/pkg/cache/redisCache"
	"strconv"
	"time"
)

// GetPasswordTryCount	获取输入次数
func GetPasswordTryCount(username string) int {
	countStr, err := redisCache.RedisDB.Get(constants.PwdErrCntCacheKey + username)
	if err != nil || len(countStr) <= 0 {
		return 0
	}
	count, err := strconv.Atoi(countStr)
	if err != nil {
		return 0
	}
	return count
}

// SetPasswordTryCount 次数+1
func SetPasswordTryCount(username string, count int) {
	redisCache.RedisDB.Put(constants.PwdErrCntCacheKey+username, strconv.Itoa(count), time.Duration(config.UserPassword.LockTime)*time.Minute)
}

// DeletePasswordTryCount 删除
func DeletePasswordTryCount(username string) {
	redisCache.RedisDB.Del(constants.PwdErrCntCacheKey + username)
}
